<?php
/**
 * The SIDN EPP Domain Info Object
 *
 * This will hold the complete Domain info SIDN can receive and give you
 *
 *
 *
 * @author Ralph de Boom <php5-sidnepp@mijndomein.nl>
 * @author Peter Keizer <php5-sidnepp@mijndomein.nl>
 * @license http://www.gnu.org/licenses/gpl-3.0.txt GNU Public License v3
 * @copyright http://www.mijndomein.nl/
 * @version 0.5
 * @link http://php5-sidnepp.svn.sourceforge.net/viewvc/php5-sidnepp/trunk/dev/docs/index.html
 * @see http://php5-sidnepp.svn.sourceforge.net/viewvc/php5-sidnepp/trunk/dev/docs/php5-sidnepp/SidnDomainInfo.html
 * @package php5-sidnepp
 */
class SidnDomainInfo {
	/**
	 *
	 * @var array
	 */
	private $contacts;


	/**
	 *
	 * @var array
	 */
	private $nameservers;

	/**
	 *
	 * @var string
	 */
	private $authorisationCode;

	/**
	 *
	 * @param SidnContact $registrant
	 * @param string $authorisationCode
	 */
	public function __construct(SidnContact $registrant = null, $authorisationCode = null)
	{
		if ($registrant)
		{
			$registrant->setContactType(SidnContact::CONTACT_TYPE_REGISTRANT);
			$this->addContact($registrant);
		}
		if ($authorisationCode)
		{
			$this->setAuthorisationCode($authorisationCode);
		}
	}

	/**
	 *
	 * @param SidnContact $contact
	 * @return void
	 */
	public function addContact(SidnContact $contact)
	{
		if (!strlen($contact->getContactType()))
		{
			throw new SidnEppException('No type of contact type set for: '.$contact->getContactHandle().', please set one!');
		}
		$this->contacts[] = $contact;
	}

	/**
	 *
	 * @param int $line
	 * @return SidnContact
	 */
	public function getContact($line)
	{
		if ($this->contacts[$line])
		{
			return $this->contacts[$line];
		}
		else
		{
			return null;
		}
	}

	/**
	 *
	 * @return int
	 */
	public function getContactLength()
	{
		return count($this->contacts);
	}

	/**
	 *
	 * @param SidnNameserverInfo $nameserver
	 * @return void
	 */
	public function addNameserver(SidnNameserverInfo $nameserver)
	{
		if (count($this->nameservers) < 13)
		{
			$this->nameservers[] = $nameserver;
		}
		else
		{
			throw new SidnEppException('Maximum nameservers for domain has been reached.');
		}
	}

	/**
	 *
	 * @return int
	 */
	public function getNameserverLength()
	{
		return count($this->nameservers);
	}

	/**
	 *
	 * @param int $line
	 * @return SidnNameserverInfo
	 */
	public function getNameserver($line)
	{
		if ($this->nameservers[$line])
		{
			return $this->nameservers[$line];
		}
		else
		{
			return null;
		}
	}

	/**
	 *
	 * @param string $authorisationCode
	 * @return void
	 */
	public function setAuthorisationCode($authorisationCode)
	{
		$this->authorisationCode = $authorisationCode;
	}
	
	/**
	 *
	 * @return string
	 */
	public function getAuthorisationCode()
	{
		return $this->authorisationCode;
	}
}
